<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // function sum(...args) {
    //   if (args.length == 0) {
    //     return 0
    //   }
      
    //   return args.pop() + sum(...args)
    // }
    // 简写
    function sum(...args) {
      if (args.length == 0) {
        return 0
      }
      
      return args.length == 0 ? 0 : args.pop() + sum(...args)
    }

    
    console.log(sum(1,2,3,4,5));
  </script>
</body>
</html>